package ga.selectionMethods;

import ga.GARun;
import ga.individuals.Individual;

import java.util.Collection;
import java.util.LinkedList;

public class EliteRoulette implements SelectionReplacementMethod {
	private Integer nForElite;
	private Integer numberOfElements;
	
	public EliteRoulette(Integer nForElite, Integer numberOfElements) throws IllegalArgumentException {
		if (nForElite < 0 || numberOfElements < 0 || numberOfElements > GARun.popSize || nForElite > numberOfElements) {
			throw new IllegalArgumentException("Invalid parameters!");
		}
		this.nForElite = nForElite;
		this.numberOfElements = numberOfElements;
	}
	
	@Override
	public Collection<Individual> method(Collection<Individual> individuals) {
		Collection<Individual> collectionEliteRoulette = new LinkedList<Individual>();
		
		Elite eliteSelection = new Elite(this.nForElite);
		collectionEliteRoulette.addAll(eliteSelection.method(individuals));
		Roulette rouletteSelection = new Roulette(this.numberOfElements - this.nForElite);
		collectionEliteRoulette.addAll(rouletteSelection.method(individuals));
		
		return collectionEliteRoulette;
	}

}
